function getParent(target, className) {
  while ((target.getAttribute("class") || "").indexOf(className) <= -1) {
    target = target.parentNode;
  }
  return target;
}
const sortHandler = (function () {
  let num = 0;
  let clickProp = "";
  return function (prop, callBack, e) {
    if (clickProp !== prop) {
      num = 0;
      clickProp = prop;
      const parent = getParent(e.target, "dv-scroll-board");      
      parent.querySelectorAll(".sort-title").forEach((target) => {
        target.removeAttribute("class");
        target.classList.add("sort-title");
      });
    }
    num++;
    if (num > 2) {
      num = 0;
    }
    const cache = {
      1: "up",
      2: "down",
    };
    const direction = cache[num] || "";
    e.target.removeAttribute("class");
    e.target.classList.add("sort-title");
    direction && e.target.classList.add(direction);
    callBack(direction, prop);
    return num;
  };
})();
const sortTitle = (title, prop, callBack) => {
  return `<span onclick="sortHandler(${prop},${callBack},event)" style="cursor:pointer" class="sort-title">${title}</span>`;
};
export { sortHandler, sortTitle };
